/*
 * Copyright (C) 2011 Mette Bank, Rikke Jensen, Kenneth Brodersen, Thomas Pedersen
 * 
 * This file is part of digiPECS.
 * 
 * digiPECS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * digiPECS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with digiPECS.  If not, see <http://www.gnu.org/licenses/>.
 */

package sw6.digipecs.helpers;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class DigiSettings {
	public static final int MODE_MULTI=1; 
	public static final int MODE_DIGI=2;
	public static final String PREF_FILE_NAME = "loaderPrefs"; 
	
	private static int mSaveMode = MODE_MULTI; 
	private Context mContext;
	private SharedPreferences mPrefs;
	private static final String HELPTEXT = "helptext"; 
	private static final String NUMBER_OF_PICTURES_BOARD = "numberoficturesboard"; 
	private static final String NUMBER_OF_PICTURES_PAGE= "numberoficturespage"; 
	
	public static void setSaveSettingsMode(int mode)
	{
		mSaveMode=mode; 
	}
	
	public DigiSettings(Context context)
	{
		mContext = context;
		mPrefs = mContext.getSharedPreferences(PREF_FILE_NAME, Context.MODE_WORLD_WRITEABLE); 
	}
	public boolean getHelpTextEnabled()
	{
		switch (mSaveMode) {
		case MODE_MULTI:
			return sw6.lib.Settings.getBoolean(mContext, HELPTEXT); 
		case MODE_DIGI:
			return mPrefs.getBoolean(HELPTEXT, true); 
		default:
			return false; 
		}
	}
	public void setHelpTextEnabled(boolean state)
	{
		switch (mSaveMode) {
		case MODE_MULTI:
			sw6.lib.Settings.setBoolean(mContext, HELPTEXT, state); 
			break;
		case MODE_DIGI:
			Editor editor = mContext.getSharedPreferences(PREF_FILE_NAME, 0).edit();
			editor.putBoolean(HELPTEXT, state);
			editor.commit();
			break;
		}
	}

	public int getNumberOfPicturesInSentence()
	{
		switch (mSaveMode) {
		case MODE_MULTI:
			int number =  sw6.lib.Settings.getInteger(mContext, NUMBER_OF_PICTURES_BOARD); 
			if(number==0)
			{
				number = 4; 
				sw6.lib.Settings.setInteger(mContext, NUMBER_OF_PICTURES_BOARD, number); 
			}
			return number; 
		case MODE_DIGI:
			return mPrefs.getInt(NUMBER_OF_PICTURES_BOARD,4); 
		default:
			return 4; 
		}
	}
	public void setNumberOfPicturesInSentence(int number)
	{
		switch (mSaveMode) {
		case MODE_MULTI:
			sw6.lib.Settings.setInteger(mContext, NUMBER_OF_PICTURES_BOARD, number); 
			break;
		case MODE_DIGI:
			Editor editor = mContext.getSharedPreferences(PREF_FILE_NAME, 0).edit();
			editor.putInt(NUMBER_OF_PICTURES_BOARD, number);
			editor.commit();
			break;
		}
	}
	
	public int getNumberOfPicturesInPage()
	{
		switch (mSaveMode) {
		case MODE_MULTI:
			int number =  sw6.lib.Settings.getInteger(mContext, NUMBER_OF_PICTURES_PAGE); 
			if(number==0)
			{
				number = 12; 
				sw6.lib.Settings.setInteger(mContext, NUMBER_OF_PICTURES_PAGE, number); 
			}
			return number; 
		case MODE_DIGI:
			return mPrefs.getInt(NUMBER_OF_PICTURES_PAGE,20); 
		default:
			return 20; 
		}
	}
	public void setNumberOfPicturesInPage(int number)
	{
		switch (mSaveMode) {
		case MODE_MULTI:
			sw6.lib.Settings.setInteger(mContext, NUMBER_OF_PICTURES_PAGE, number); 
			break;
		case MODE_DIGI:
			Editor editor = mContext.getSharedPreferences(PREF_FILE_NAME, 0).edit();
			editor.putInt(NUMBER_OF_PICTURES_PAGE, number);
			editor.commit();
			break;
		}
	}
}

